package cn.edu.lingnan.mapper;

import cn.edu.lingnan.user.dtos.UpdateUserDTO;
import cn.edu.lingnan.user.dtos.UserQueryDTO;
import cn.edu.lingnan.user.pojos.User;
import cn.edu.lingnan.user.vos.UserInfoVo;
import cn.edu.lingnan.user.vos.UserVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    Page getUserList(UserQueryDTO queryDTO);

    @Update("UPDATE t_user SET del_flag = 1 WHERE user_id = #{userId}")
    int updateUserDelFlag(@Param("userId") int userId);

    int updateUser(UpdateUserDTO updateUserDTO);

    @Select("SELECT * FROM t_user WHERE del_flag = 0")
    List<UserVO> getAllUsers();

    int updateStatus(Integer userId, Integer status);

    @Update("UPDATE t_user SET avatar = #{url} WHERE user_id = #{userId}")
    void updateUserImage(Long userId, String url);

    UserVO getUserById(Integer userId);


    int insert(User user);

    void insertUserRole(Integer userId, Integer type);

    List<User> getUserBytype(Integer type);


    // 根据 userName 查询用户信息
    UserInfoVo getUserByUserName(@Param("userName") String userName);
    @Select("SELECT type FROM tb_exam_system.t_user WHERE user_id = #{userId}")
    Integer getUserTypeByUserId(Integer currentId);
    List<User> getUserByExamId(Integer examId);

    UserInfoVo getPasswordByUserId(@Param("userId") String userId);

    int updatePassword(@Param("userId") String userId, @Param("newPassword") String newPassword);

    @Delete("DELETE FROM  t_user_role WHERE user_id = #{userId}")
    void deleteUserRole(Integer userId);

    @Select("SELECT * FROM t_user WHERE email = #{email}")
    UserInfoVo  getUserByEmail(String email);

    @Select("SELECT role_id FROM t_user_role WHERE user_id = #{userId}")
    Integer getUserRole(Integer currentId);
}
